package j2025.j02;

import java.util.HashSet;

/**
 * @Author 猫大仙
 */
public class j0223 {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int ret = 0;
        for(int a:set){
            if(!set.contains(a-1)){
                int tmp = a;
                int len = 1;
                while(set.contains(tmp+1)){
                    len++;
                    tmp++;
                }
                ret = Math.max(ret, len);
            }
        }
        return ret;
    }
}
